package com.chuji.crmcj.adapter;

import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.JsonObjectRequest;
import com.android.volley.toolbox.StringRequest;
import com.chuji.crmcj.utils.UIUtils;
import com.chuji.crmcj.utils.VolleyUtil;

import org.json.JSONObject;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by w.pitt on 2016/2/18.
 */
public class CustomeAdapter extends BaseAdapter{
    @Override
    public int getCount() {
        return 0;
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        return null;
    }

    /**
     * 抽取网络请求
     */
    public void volleyRequest(String url,Response.Listener<String> listener){
        StringRequest request = new StringRequest(Request.Method.GET, url, listener, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError volleyError) {
                UIUtils.showToastSafe("失败" + volleyError);
            }
        });
        VolleyUtil.getRequestQueue().add(request);
    }

    /**
     * post  Object 请求
     *
     * @param url
     * @param obj
     * @param listener
     */
    public void postRequest(String url, Map<String, String> obj, Response.Listener<JSONObject> listener) {
//        Map<String, String> obj = new HashMap<String, String>();
//        obj.put("SalesID", "F248611C-CB39-4806-919E-71DCD085D208");
        Map<Object, Object> params = new HashMap<Object, Object>();
        params.put("ApiParamObj", obj);
        params.put("ErrCode", "0");
        params.put("Message", "POST");
        params.put("Success", "1");
        JsonObjectRequest jsonObjReq = new JsonObjectRequest(Request.Method.POST, url, new JSONObject(params), listener, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                UIUtils.showToastSafe("失败" + error.toString());
            }
        });
        VolleyUtil.getRequestQueue().add(jsonObjReq);
    }

}
